package BookTest;

public class G4Shop {
    private double weight;
    private final double preice500g=3.98;

    public G4Shop(double weight) {
        this.weight = weight;
    }
    public double getWeight() {
        return weight;
    }
    public void setWeight(double weight) {
        this.weight = weight;
    }
    public double getPreice500g() {
        return preice500g;
    }
    public void getshop(){
        if(weight <1500 && weight > 0){
            double amount = weight /500* preice500g;
            System.out.println(amount);
        }else if(weight >=1500) {
            try {
                double remainingWeight = weight - 1500;
                System.out.println("超出1500克的重量为：" + remainingWeight);
                double amount = 1500 / 500 * preice500g;
                System.out.println("计算出满足1500克所付出的金额为：" + amount);
            } catch (Exception e) {
                System.out.println("重量超出1500");
            }
        }
        else{
            System.out.println("重量不能为负数");
        }
    }
}
